
// 动态原型模式：可以通过检查某个应该存在的方法是否存在，来决定是否需要初始化原型

function Person(name,age,job){
    // 属性
    this.name = name;
    this.age = age;
    this.job = job;

    // 方法
    if(typeof this.sayName != 'function'){
        Person.prototype.sayName = function(){
            console.log(this.name);
        }
    }
}

var friend = new Person('lili',19,'doctor')
console.log(friend); // { name: 'lili', age: 19, job: 'doctor' }
friend.sayName(); // lili

var friend2 = new Person('luna',18,'dancer')
friend2.sayName = function(){
    console.log('my name is:'+this.name);
}
console.log(friend2); // { name: 'luna', age: 18, job: 'dancer', sayName: [Function] }
friend2.sayName(); // my name is:luna